using ChikovMF.Application.Features.Tags.EditTag;
using Microsoft.EntityFrameworkCore;

namespace ChikovMF.Tests.Tags.Commands;

public class EditTagTest : TestCommandBase
{
    [Fact]
    public async Task EditTagTest_Success()
    {
        var handler = new EditTagCommandHandler(_context);
        var command = new EditTagCommand
        {
            Name = "editTagName",
            TagId = new Guid("a3446f5d-5e34-4ae9-aef9-fe0b584bb9cd")
        };
        var oldTag = await _context.Tags.FirstOrDefaultAsync(tag => tag.TagId == command.TagId);
        

        var editTagId = await handler.Handle(
            command,
            CancellationToken.None
        );


        Assert.NotNull(oldTag);
        var editTag = await _context.Tags.FirstOrDefaultAsync(tag => tag.TagId == command.TagId);
        Assert.NotNull(editTag);

        Assert.Equal(command.Name, editTag.Name);
        Assert.Equal(command.TagId, editTagId);
        Assert.Equal(oldTag.TagId, editTag.TagId);
    }
}